﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Compression;

namespace GZip
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            toolStripComboBox1.Items.Clear();
            EncodingInfo[] es = Encoding.GetEncodings();
            int index = -1;
            foreach (EncodingInfo ei in es)
            {
                int x = toolStripComboBox1.Items.Add(ei.Name);
                if (index == -1)
                {
                    if (ei.Name == "utf-8")
                        index = x;
                }
            }
            toolStripComboBox1.SelectedIndex = index;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                byte[] bs = WFNetLib.Strings.StringsFunction.strToHexByte(textBox1.Text, " ");
                MemoryStream ms = new MemoryStream(bs, 0, bs.Length);
                GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress);
                //string str = http.ContentEncoding.GetString(http.ContentDatas.ToArray());
                Encoding ContentTypeCharset = Encoding.GetEncoding(toolStripComboBox1.Text);
                StreamReader reader;
                if (ContentTypeCharset != null)
                    reader = new StreamReader(gzip, ContentTypeCharset);
                else
                    reader = new StreamReader(gzip);
                string str = reader.ReadToEnd();
                textBox2.Text = str;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
